<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>学生期末成绩报告-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<script src="<%=basePath %>/js/echarts-3.8.4.js"></script>
<script src="<%=basePath %>/js/picker.js"></script>
<script src="<%=basePath %>/js/select.js"></script>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"> <a onclick="back()" href="javascript:;" class="icon icon-109 f-white">返回</a> </div>
	    	<h1 class="weui-header-title" ><span class="schoolYear"></span>期末成绩报告</h1>
	    	<div class="weui-header-right">
	    		<i class="icon icon-74"></i>
	    		<input type="text" id="schoolYear" readonly style="position: absolute;top: 0;opacity: 0;">
	    	</div>
	    </div>
		<div class="weui_tab_bd">
			<div class="weui_cells afterNone afterNoneBefore mt0">
				<div class="weui_cell bd-t0">
					<div class="weui_cell_hd weui_center_50">
						${student.gradeName }(${student.clazz })班
					</div>
					<div class="weui_cell_hd weui_center_50">
						${student.name }
					</div>
				</div>
			</div>
			<div id="reportResult">
			</div>
	        
	     <script id="report-table-template" type="text/x-handlebars-template">
	        <div class="weui_cells bd-t0 mt5 mb10">
		        <div class="weui_cell lblue bd-t0"> 
		            <div class="weui_cell_bd weui_cell_primary">
		                <p class="">学科成绩</p>
		            </div>
		        </div>
		        <div class="weui_cell bd-t0" style="padding:0;"> 	        	
					<table class="weui-table weui-border-tb">
	                	<thead>
			                <tr>
				                <th width="20%">学科</th>
				                <th width="20%">平时<br/>成绩</th>
				                <th width="20%">期末<br/>成绩</th>
				                <th width="20%">总评<br/>成绩</th>
				                <th width="20%">期末级<br/>平均分</th>
			                </tr>
		                </thead>
		                <tbody>
		                	<tr>
		                		<td>政治</td>
		                		<td>{{politicsNormalScore}}</td>
		                		<td>{{politicsFinalTermScore}}</td>
		                		<td>{{politicsTotalAvgScore}}</td>
		                		<td>{{politicsFinalTermGradeAvgScore}}</td>
		                	</tr>
		                	<tr>
		                		<td>语文</td>
		                		<td>{{chineseNormalScore}}</td>
		                		<td>{{chineseFinalTermScore}}</td>
		                		<td>{{chineseTotalAvgScore}}</td>
		                		<td>{{chineseFinalTermGradeAvgScore}}</td>
		                	</tr>
		                	<tr>
		                		<td>数学</td>
		                		<td>{{mathNormalScore}}</td>
		                		<td>{{mathFinalTermScore}}</td>
		                		<td>{{mathTotalAvgScore}}</td>
		                		<td>{{mathFinalTermGradeAvgScore}}</td>
		                	</tr>
		                	<tr>
		                		<td>英语</td>
		                		<td>{{englishNormalScore}}</td>
		                		<td>{{englishFinalTermScore}}</td>
		                		<td>{{englishTotalAvgScore}}</td>
		                		<td>{{englishFinalTermGradeAvgScore}}</td>
		                	</tr>
		                	<tr>
		                		<td>生物</td>
		                		<td>{{biologyNormalScore}}</td>
		                		<td>{{biologyFinalTermScore}}</td>
		                		<td>{{biologyTotalAvgScore}}</td>
		                		<td>{{biologyFinalTermGradeAvgScore}}</td>
		                	</tr>
		                	<tr>
		                		<td>物理</td>
		                		<td>{{phyticsNormalScore}}</td>
		                		<td>{{phyticsFinalTermScore}}</td>
		                		<td>{{phyticsTotalAvgScore}}</td>
		                		<td>{{phyticsFinalTermGradeAvgScore}}</td>
		                	</tr>
		                	<tr>
		                		<td>化学</td>
		                		<td>{{chemistryNormalScore}}</td>
		                		<td>{{chemistryFinalTermScore}}</td>
		                		<td>{{chemistryTotalAvgScore}}</td>
		                		<td>{{chemistryFinalTermGradeAvgScore}}</td>
		                	</tr>
		                	<tr>
		                		<td>历史</td>
		                		<td>{{historyNormalScore}}</td>
		                		<td>{{historyFinalTermScore}}</td>
		                		<td>{{historyTotalAvgScore}}</td>
		                		<td>{{historyFinalTermGradeAvgScore}}</td>
		                	</tr>
		                	<tr>
		                		<td>地理</td>
		                		<td>{{geographyNormalScore}}</td>
		                		<td>{{geographyFinalTermScore}}</td>
		                		<td>{{geographyTotalAvgScore}}</td>
		                		<td>{{geographyFinalTermGradeAvgScore}}</td>
		                	</tr>
		                	<tr>
		                		<td>体育</td>
		                		<td>{{sportsNormalScore}}</td>
		                		<td>{{sportsFinalTermScore}}</td>
		                		<td>{{sportsTotalAvgScore}}</td>
		                		<td></td>
		                	</tr>
		                	<tr>
		                		<td>音乐</td>
		                		<td></td>
		                		<td></td>
		                		<td>{{musicTotalAvgScore}}</td>
		                		<td></td>
		                	</tr>
		                	<tr>
		                		<td>美术</td>
		                		<td></td>
		                		<td></td>
		                		<td>{{artTotalAvgScore}}</td>
		                		<td></td>
		                	</tr>
		                	<tr>
		                		<td>信息技术</td>
		                		<td>{{infomationNormalScore}}</td>
		                		<td>{{infomationFinalTermScore}}</td>
		                		<td>{{infomationTotalAvgScore}}</td>
		                		<td></td>
		                	</tr>
		                	<tr>
		                		<td>综合实践</td>
		                		<td></td>
		                		<td></td>
		                		<td>{{synthesizeTotalAvgScore}}</td>
		                		<td></td>
		                	</tr>
							<tr>
		                		<td>语文口语</td>
		                		<td>{{chineseLanguage}}</td>
		                		<td colspan="2">英语口语</td>
		                		<td>{{englishLanguage}}</td>
		                	</tr>
		                	<tr>
		                		<td>操行分</td>
		                		<td>{{conductScore}}</td>
		                		<td colspan="2">德育等级评定</td>
		                		<td>{{moralEducationLevel}}</td>
		                	</tr>
		                </tbody>
	            	</table>
	            </div>
	        </div>
		    <div class="weui_cells bd-t0 mt0 mb10">
		        <div class="weui_cell lblue bd-t0"> 
		            <div class="weui_cell_bd weui_cell_primary">
		                <p class="">获奖情况</p>
		            </div>
		        </div>
		        <div class="weui_cell">
		        	{{prizeItems}}
		        </div>
		    </div>
		    <div class="weui_cells bd-t0 mt0 mb40">
		        <div class="weui_cell lblue bd-t0"> 
		            <div class="weui_cell_bd weui_cell_primary">
		                <p class="">班主任评语</p>
		            </div>
	          	</div>
	          	<div class="weui_cell">
		        	{{teacherComment}}
		        </div>
		    </div>
		</script>
		</div>
	</div>
</body>
<script type="text/javascript">
	$(function() {
		termList();
	})
	var map = new Map();
	var termName;
	function termList() {
		$.ajax({
    		url: basePath + "/studentTermList",
    		type: 'GET',
    		dataType : "json",
    		data: {
    			grade: "${student.grade}"
    		},
    		success: function(data) {
    			var termList = [], termTypeList = ["上", "下"];
    			for(var i in data) {
    				if(i == 0) {
    					termName = data[i].termName;
    					scoreReport(data[i].id, parseInt(new Date().getMonth() + 1) >= 7 ? "下" : "上");
    				}
    				map.set(data[i].termName, data[i].id);
    				termList.push(data[i].termName);
    			}
    			$("#schoolYear").picker({
    		        title: "请选择学年",
    		        onClose:function(){
    		        	var termName = this.cols[0].displayValue;
    		        	var termType = this.cols[1].displayValue;
    		        	scoreReport(map.get(termName), termType);
    		        },
    		        cols: [
    		          {
    		            textAlign: 'center',
    		            values: termList
    		          },
    		          {
    		            textAlign: 'center',
    		            values: termTypeList
    		          }
    		        ]
    		      });
    			
    		},
    		error: function(data) {
    			$.alert("系统异常,请联系管理员", "");
    		}
    	});
	}
	function scoreReport(termId, termType) {
		$.ajax({
    		url: basePath + "/finalTermScore/studentReport/query",
    		type: 'POST',
    		dataType : "json",
    		data: {
    			studentId: "${student.id}",
    			termId: termId,
    			termType: termType
    		},
    		success: function(rspData) {
    			if(rspData == null){
    				$.alert("暂无成绩报告数据!", "");
    				return;
    			}
    			$(".schoolYear").html(termName + "("+ termType +")");
    			loadReportHtml(rspData);
    		},
    		error: function(data) {
    			$.alert("系统异常,请联系管理员", "");
    		}
    	});
	}
	function loadReportHtml(report) {
		var myTemplate = Handlebars.compile($("#report-table-template").html());
		Handlebars.registerHelper("equal", function(v1,v2,options) {
    		if(v1 == v2) {
    			//满足添加继续执行
    			return options.fn(this);
    		}else {
    			//不满足条件执行{{else}}部分
    			return options.inverse(this);
    		}
    	});
		$('#reportResult').html(myTemplate(report));
	}
</script>
</html>